{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Displaying molecular orbitals with chemlab and chemview"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from chemview import MolecularViewer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from chemlab.io import remotefile\n",
    "from chemlab.core import guess_bonds\n",
    "# pull the file\n",
    "df = remotefile('https://raw.githubusercontent.com/cclib/cclib/master/data/GAMESS/basicGAMESS-US2012/Trp_polar_tdhf.out', 'gamess')\n",
    "\n",
    "mo_coefficients = df.read('mocoeffs')\n",
    "gbasis = df.read('gbasis')\n",
    "molecule = df.read('molecule')\n",
    "molecule.bonds = guess_bonds(molecule.r_array, molecule.type_array, threshold=0.05)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from chemlab.qc import molecular_orbital\n",
    "\n",
    "f = molecular_orbital(molecule.r_array, mo_coefficients[0][-1], gbasis)\n",
    "\n",
    "mv = MolecularViewer(molecule.r_array, {'atom_types': molecule.type_array,\n",
    "                                        'bonds': molecule.bonds})\n",
    "mv.wireframe()\n",
    "mv.add_isosurface(f, isolevel=0.3, color=0xff0000)\n",
    "mv.add_isosurface(f, isolevel=-0.3, color=0x0000ff)\n",
    "\n",
    "mv"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
